home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Sample Code / Pascal Sample 3.0B10 / Source / TrafficLights.p < prev   
Encoding:
Text File  |  1993-10-13  |  27.6 KB  |  663 lines  |  [TEXT/MPS ]

  1. (******************************************************************************
  2. *
  3. *    Apple Macintosh Developer Technical Support
  4. *
  5. *    Interfaces for the traffic light code
  6. *
  7. *    Program:    Sample 3.0
  8. *    FILE:        TrafficLights.p - Pascal implementation
  9. *
  10. *    by:            Matt Deatherage
  11. *
  12. *    Copyright © 1988-1993 Apple Computer, Inc.
  13. *    All rights reserved.
  14. *
  15. *******************************************************************************
  16. * This is the biggest of the units in Sample 3.0 -- the unit that handles
  17. * all the documents, the circles, the traffic lights, the drawing to the
  18. * screen (including color, multiple monitors, DeviceLoop and more).  This
  19. * code saves files to disk, reads files from disk, reads and writes the
  20. * preferences file, handles balloon help for our windows, creates and
  21. * destroys all windows, and more.
  22. *
  23. * Originally, I intended all of the "application-specific" stuff to be in
  24. * this unit -- anything that would have to change if you were changing
  25. * Sample's documents to be something other than traffic lights would be
  26. * in this unit.  To a large degree I met that goal, but in some places it
  27. * would have added extra layers of indirection that, in the end, I felt
  28. * weren't necessary.  You'll see some empty procedures in here because the
  29. * "shell" functions in Sample.p call them (for example, RemoveAppAEHandlers,
  30. * which is supposed to remove any Apple event handlers that are application-
  31. * specific, but we don't have any).
  32. *
  33. * This unit defines two primary data types.  The "CircleRec" is a record
  34. * containing everything needed to define a circle -- its rectangle, font,
  35. * text, text style, size and the color of the circle.  The "document" is
  36. * a structure that includes an array of CircleRec records, plus a count
  37. * of how many circles are really there, which one is the active one, and
  38. * other document-specific data like a print record, a dirty flag, a reference
  39. * number for open files and a FileLikeSpec to point to the file on disk.
  40. * (FileLikeSpec records are defined in SampleUtilities.p.)
  41. *
  42. * Since this is Pascal, and we have to declare a size for a record, we
  43. * have a kMaxCircles constant (10) -- there are always ten circle records in
  44. * a document, even if the preferences specify a maximum of zero.  The prefs
  45. * just let the user limit what actions can be performed.  It would be cool
  46. * to have the document record just contain pointers to circle records, and
  47. * then we could have a maximum of several dozen without taking as much space
  48. * as one circle record -- but that wouldn't be much help unless we also added
  49. * the ability to resize the window and/or scroll it.
  50. *
  51. * Another good change would be to have the document for each window, which
  52. * is attached via the window's refCon field, as a handle instead of a pointer.
  53. * Right now, all documents are created with NewPtr and never move.  We manage
  54. * memory well enough that this doesn't cause fragmentation, and we know that
  55. * each document's size does not change after it is created, so this actually
  56. * works OK for us, but many applications will need more flexible document
  57. * sizes and will need to use resizeable handles, keeping them unlocked except
  58. * when in use to reduce memory fragmentation.
  59. *
  60. ******************************************************************************)
  61.  
  62. UNIT TrafficLights; { unit to deal with the traffic lights in Sample }
  63.  
  64. INTERFACE
  65.  
  66. (*******************************************************************************
  67. * Used Units
  68. *******************************************************************************)
  69.  
  70. USES Traps, Types, Errors, Resources, ToolUtils, Fonts, Files, Finder, Folders,
  71.      QDOffScreen, Balloons, Picker, PrintTraps, StandardFile, AppleTalk,
  72.      Processes, PPCToolbox, EPPC, Notification, AppleEvents, Features,
  73.      SampleUtilities;
  74.  
  75. (*******************************************************************************
  76. * Constants
  77. *******************************************************************************)
  78.  
  79. CONST 
  80.  
  81.     { Constants dealing with defaults }
  82.     
  83.     kMaxCircles = 10;            { For static arrays, there has to be a limit }
  84.     kDefaultNum = 3;            { Default number of circles per document }
  85.     rWindow = 128;                 { The 'WIND' resource we use }
  86.     
  87.     rDefaultFonts = 1000;         { 'STR#' resource ID with default font names }
  88.     rDefaultStrings = 1001;     { 'STR#' resource ID with default circle texts }
  89.     rDefaultSizes = 1000;         { 'DfSz' resource with default text sizes }
  90.     rDefaultColorID = 1000;     { 'RGB ' resource with default color }
  91.     
  92.     { Constants for alerts for errors we might encounter }
  93.     
  94.     rNoMemForWindow = 2000;             { No memory for new window or document }
  95.     rReallyRevert = 2010;                 { Alert asking if it's OK to revert }
  96.     rNoMemoryForOperation = 2011;        { No memory to do that operation }
  97.  
  98.     { Constants having to do with the preferences file }
  99.     
  100.     rPrefsFileName = 128;                 { 'STR ' resource containing the 
  101.                                           preferences file name }
  102.     kSamplePrefsType = 'Pref';             { file type of our preferences file }
  103.     kSamplePrefsRsrc = 'Pref';            { res type of the prefs resource in it }
  104.     rSamplePrefsID = 128;                 { our preference resource ID }
  105.  
  106.     { Constants for the files we save }
  107.     
  108.     kOurCreatorType = 'DSp1';             { OSType for our creator type }
  109.     kOurDocumentType = 'DSp1';            { file type for our documents -- 
  110.                                           p for Pascal, which came first }
  111.     kFileInternalVersion = $0001;         { internal version number for our file
  112.                                           format; we can't read files if the
  113.                                           version inside is bigger than this
  114.                                           value }
  115.     rMiscStrings = 1004;                { Miscellaneous strings }
  116.     kSaveFileAs = 1;                    { "Save current document as:" }
  117.     kPickColor = 2;                        { "Select a color for this circle." }
  118.  
  119.     { Options for the dirty flag for documents }
  120.  
  121.     kDocumentDirty = 1;                    { Document needs saving to disk }
  122.     kDocumentNew = 2;                     { Document is new -- enable save but
  123.                                           don't prompt to save when closing }
  124.     kDocumentClean = 3;                    { Document is saved to disk }
  125.  
  126.     kActiveCircleBalloonString = 43;    { Balloon help string for active circle }
  127.     kInactiveCircleBalloonString = 44;    { Balloon help string for inactive one }
  128.     rBalloonHelpStringID = 5000;        { 'STR#' with most balloon help strings }
  129.  
  130.     { Constants for memory cushions and safeguards }
  131.  
  132.     kDialogMemorySize = 16 * 1024;         { We require this much memory available
  133.                                           in our heap to do the modify circle or
  134.                                           preferences dialogs, realistically }
  135.     kMemoryCushionSize = 16 * 1024;     { To keep breathing room in our heap,
  136.                                           we won't open a new window unless this
  137.                                           much space is available in our heap. }
  138.  
  139.     { Constants defining TrafficLight-specific menus.  Menus start with "m"
  140.       and items start with "i". }
  141.       
  142.     mCircle = 131;
  143.     iAdd = 1;
  144.     iModify = 2;
  145.     iDelete = 3;
  146.  
  147. (*******************************************************************************
  148. * Types
  149. *******************************************************************************)
  150.  
  151. TYPE
  152.  
  153. (*******************************************************************************
  154. * Each circle record contains all the visual aspects of a traffic light we
  155. * might want to draw.
  156. *******************************************************************************)
  157.  
  158.     CircleRec = RECORD
  159.         circleRect: Rect;                 { The rectangle for the circle 
  160.                                           (and FrameOval) }
  161.         circleFont: Str255;             { font family name for this circle's
  162.                                           font }
  163.         circleText: Str255;             { string to display in this circle }
  164.         circleFace: Style;                 { Style for text in circle }
  165.         circleTxSize: INTEGER;             { Size for text in circle }
  166.         circleColor: RGBColor;            { color of circle's background }
  167.         END;
  168.     CircleRecPtr = ^CircleRec;
  169.  
  170. (*******************************************************************************
  171. * The document record contains a bunch of circles plus other information
  172. * necessary to keep with each document.
  173. *******************************************************************************)
  174.  
  175.     document = RECORD
  176.         numCircles: INTEGER;            { how many circles in this document? }
  177.         activeCircle: INTEGER;            { which one is the active one? }
  178.         printRecord: THPrint;            { the document's print record -- always
  179.                                           keep one with a document so the user's
  180.                                           Page Setup choices aren't lost }
  181.         dirtyFlag: INTEGER;                { Is this document written to disk? }
  182.         circleInset: INTEGER;            { How much to inset a circle }
  183.         ourFileRefNum: INTEGER;            { refNum of file if open, or zero if
  184.                                           this isn't an open file }
  185.         ourFile: FileLikeSpec;            { FSSpec describing file on disk }
  186.         circleArray: ARRAY [1..kMaxCircles] OF CircleRec;
  187.                                         { all the circles in this document }
  188.         END;
  189.     DocumentPtr = ^document;
  190.  
  191. (*******************************************************************************
  192. * The Preferences record describes all the user-editable preferences.  It might
  193. * have been easier to keep three global variables, but having this record
  194. * allows us to write generic preference-manipulating routines that take or
  195. * return records as parameters.
  196. *******************************************************************************)
  197.  
  198.     Preferences = RECORD
  199.         maxNumCircles: INTEGER;            { how many circles can we allow in this
  200.                                           document? }
  201.         circleRectSize: INTEGER;        { Rectangle for default document circles }
  202.         circleInsetSize: INTEGER;        { Inset for default document circles }
  203.         END;
  204.  
  205. (*******************************************************************************
  206. * The LightConditions record keeps track of three state variables for each
  207. * circle record, and is used as a container to pass to light-drawing functions.
  208. * If the light is "on", that means it's the one that currently has the black
  209. * frame, the colored background and the text is showing -- unless it's not
  210. * "active", in which case you see the frame and the text but nothing else.
  211. * If a light is not on and not active, you see nothing.  We also note if
  212. * this light is being printed so we can do things differently while printing
  213. * if necessary (like not erasing rectangles, or being careful about non-
  214. * rectangular clipping regions for PostScript printers).
  215. *******************************************************************************)
  216.  
  217.     LightConditions = RECORD
  218.         itsOn: BOOLEAN;                    { is this light the current one? }
  219.         itsActive: BOOLEAN;                { is it in an active window? }
  220.         arePrinting: BOOLEAN;            { are we printing? }
  221.         theCircle: CircleRecPtr;        { which light are we talking about? }
  222.         END;
  223.     LightConditionsPtr = ^LightConditions;
  224.  
  225. (*******************************************************************************
  226. * Global variables maintained by this unit
  227. *******************************************************************************)
  228.  
  229. VAR 
  230.  
  231.     gPrefsRecord: Preferences;             { our preferences for this session }
  232.  
  233. (*******************************************************************************
  234. *
  235. * AddDefaultCircle - add a new circle to a document.
  236. *
  237. * This routine gets a new default circle (using defaults in the resource fork)
  238. * and adds it to the window, resizing it as required to show the new circle.
  239. *
  240. *******************************************************************************)
  241.  
  242. PROCEDURE AddDefaultCircle(theDoc: DocumentPtr; theWindow: WindowPtr);
  243.  
  244. (*******************************************************************************
  245. *
  246. * GetDocumentDrawingSize - determine the area of this document.
  247. *
  248. * This routine examines a document structure and fills in a Point whose .h 
  249. * member has the width of this document, in pixels, and whose .v member has
  250. * the height.
  251. *
  252. *******************************************************************************)
  253.  
  254. PROCEDURE GetDocumentDrawingSize(theDoc: DocumentPtr; VAR theSize: Point);
  255.  
  256. (*******************************************************************************
  257. *
  258. * DeleteActiveCircle - remove a circle from a window.
  259. *
  260. * This routine, called in response to the "Delete Circle" menu item, removes
  261. * the currently active circle from the window's document, resizes the window
  262. * and invalidates it.  The new active circle is the previous circle.
  263. *
  264. *******************************************************************************)
  265.  
  266. PROCEDURE DeleteActiveCircle(theWindow: WindowPtr);
  267.  
  268. (*******************************************************************************
  269. *
  270. * RemoveAppAEHandlers - deinstall any application-specific Apple Event handlers.
  271. *
  272. *******************************************************************************)
  273.  
  274. PROCEDURE RemoveAppAEHandlers;
  275.  
  276. (*******************************************************************************
  277. *
  278. * InstallAppAEHandlers - install any application-specific Apple Event handlers.
  279. *
  280. *******************************************************************************)
  281.  
  282. PROCEDURE InstallAppAEHandlers;
  283.  
  284. (*******************************************************************************
  285. *
  286. * InitializeApplication - perform application-specific startup tasks
  287. *
  288. * This routine performs initialization tasks specific to our application.
  289. * in this particular case, we get the preferences from disk, initialize
  290. * the window count to zero and use the Segment Loader functions to open any
  291. * files that the user may have double-clicked on in a system without the
  292. * Apple Event Manager.  Returns TRUE if we started up just fine.
  293. *
  294. *******************************************************************************)
  295.  
  296. FUNCTION InitializeApplication: BOOLEAN;
  297.  
  298. (*******************************************************************************
  299. *
  300. * TerminateApplication - perform application-specific teardown tasks
  301. *
  302. * This routine performs any application-specific teardown tasks, releasing
  303. * memory, etc.  If we can't quit at this point for some reason, this routine
  304. * must return FALSE.
  305. *
  306. *******************************************************************************)
  307.  
  308. FUNCTION TerminateApplication: BOOLEAN;
  309.  
  310. (*******************************************************************************
  311. *
  312. * DrawWindow - draw a given window's document into a given GrafPort
  313. *
  314. * This routine fetches a window's document and draws it into the window. If
  315. * the supplied drawingPort parameter is not NIL, we draw into that GrafPort
  316. * instead, which can be handy for printing and other redirections.  The
  317. * "printing" BOOLEAN is TRUE if we're printing; the isActive parameter is TRUE
  318. * if this should be drawn as if it were an active window.
  319. *
  320. *******************************************************************************)
  321.  
  322. PROCEDURE DrawWindow(window: WindowPtr; drawingPort: GrafPtr; printing: BOOLEAN;
  323.                      isActive: BOOLEAN);
  324.  
  325. (*******************************************************************************
  326. *
  327. * ChangeCircleColor - ask the user for a new circle color
  328. *
  329. * This routine calls the Macintosh Color Picker to present the color choice
  330. * dialog on the user's deepest screen, storing the user's color choice in
  331. * the circle record if the user confirms the dialog.
  332. *
  333. * Don't call this routine if Color QuickDraw isn't installed.
  334. *
  335. *******************************************************************************)
  336.  
  337. PROCEDURE ChangeCircleColor(theCircle: CircleRecPtr);
  338.  
  339. (*******************************************************************************
  340. *
  341. * ChangeCircleFont - replace a circle record's font
  342. *
  343. * This setter function changes a circle record to contain a new font name.
  344. *
  345. *******************************************************************************)
  346.  
  347. PROCEDURE ChangeCircleFont(theCircle: CircleRecPtr; theNewFontName: Str255);
  348.  
  349. (*******************************************************************************
  350. *
  351. * ChangeCircleTxSize - replace a circle record's text size
  352. *
  353. * This setter function changes a circle record to contain a new font size.
  354. *
  355. *******************************************************************************)
  356.  
  357. PROCEDURE ChangeCircleTxSize(theCircle: CircleRecPtr; theNewSize: INTEGER);
  358.  
  359. (*******************************************************************************
  360. *
  361. * ChangeCircleText - replace a circle record's text string
  362. *
  363. * This setter function changes a circle record to contain a new string.
  364. *
  365. *******************************************************************************)
  366.  
  367. PROCEDURE ChangeCircleText(theCircle: CircleRecPtr; theNewText: Str255);
  368.  
  369. (*******************************************************************************
  370. *
  371. * ChangeCircleStyle - replace a circle record's text style
  372. *
  373. * This setter function changes a circle record to contain a new font style.
  374. *
  375. *******************************************************************************)
  376.  
  377. PROCEDURE ChangeCircleStyle(theCircle: CircleRecPtr; theNewStyle: Style);
  378.  
  379. (*******************************************************************************
  380. *
  381. * GetDocumentDirtyFlag - return a document's dirty flag
  382. *
  383. * This getter function returns a document's dirty flag, so external routines
  384. * don't have to peek directly into document structures.
  385. *
  386. *******************************************************************************)
  387.  
  388. FUNCTION GetDocumentDirtyFlag(theDoc: DocumentPtr): INTEGER;
  389.  
  390. (*******************************************************************************
  391. *
  392. * SetDocumentDirtyFlag - sets a document's dirty flag
  393. *
  394. * This setter function sets a document's dirty flag, so external routines
  395. * don't have to poke directly into document structures.
  396. *
  397. *******************************************************************************)
  398.  
  399. PROCEDURE SetDocumentDirtyFlag(theDoc: DocumentPtr; theFlag: INTEGER);
  400.  
  401. (*******************************************************************************
  402. *
  403. * InvalidateCircle - invalidate's a circle's rectangle
  404. *
  405. * This routine invalidates the rectangle for a circle in the current GrafPort,
  406. * hopefully making it be redrawn on the next update event.
  407. *
  408. *******************************************************************************)
  409.  
  410. PROCEDURE InvalidateCircle(theCircle: CircleRecPtr);
  411.  
  412. (*******************************************************************************
  413. *
  414. * DrawDocument - draw a document structure into a given GrafPort
  415. *
  416. * DrawDocument draws a document (not a window) into a given GrafPort, and can
  417. * be called by functions to draw windows, print, make pictures or anything
  418. * else that needs an image of a document structure.  printing is TRUE if the
  419. * drawing routines should act as if they're printing; isActive is TRUE if the
  420. * document should be drawn as if it were an active window.
  421. *
  422. *******************************************************************************)
  423.  
  424. PROCEDURE DrawDocument(theDoc: DocumentPtr; drawingPort: GrafPtr; printing,
  425.                        isActive: BOOLEAN);
  426.  
  427. (*******************************************************************************
  428. *
  429. * DrawLight - draw a single light
  430. *
  431. * DrawLight does the real work -- it takes a LightConditions record describing
  432. * how a CircleRec should appear and draws it, using color on color systems,
  433. * optimizing depth on multiple monitors and adjusting the color of the text
  434. * string so it's white if on a dark background, and black if on a light
  435. * background.  If there is no color, active circles are always white text
  436. * on a black background.
  437. *
  438. *******************************************************************************)
  439.  
  440. PROCEDURE DrawLight(myLight: LightConditions);
  441.  
  442. (*******************************************************************************
  443. *
  444. * CloseAppWindow - close a document window
  445. *
  446. * Called by Sample.p when it needs to close a window belonging to the program,
  447. * this routine checks the dirty flag of the window's document and prompts
  448. * for saving if the document is dirty, saving the file to disk if the user
  449. * wants it saved.  action is either kClosing or kQuitting.  CloseAppWindow
  450. * returns TRUE if the window was succesfully closed and its structures
  451. * disposed safely.
  452. *
  453. *******************************************************************************)
  454.  
  455. FUNCTION CloseAppWindow(theWindow: WindowPtr; action: INTEGER): BOOLEAN;
  456.  
  457. (*******************************************************************************
  458. *
  459. * PutPrefsToFile - write a preferences record to an open file on disk
  460. *
  461. * This routine writes the preferences record thePrefs to the open file whose
  462. * reference number is theRefNum.
  463. *
  464. *******************************************************************************)
  465.  
  466. PROCEDURE PutPrefsToFile(thePrefs: preferences; theRefNum: INTEGER);
  467.  
  468. (*******************************************************************************
  469. *
  470. * MakeWindowFromDoc - Create a window for a document structure
  471. *
  472. * MakeWindowFromDoc creates a window and changes its parameters to fit the
  473. * document whose pointer is the only parameter.
  474. *
  475. *******************************************************************************)
  476.  
  477. FUNCTION MakeWindowFromDoc(theDoc: DocumentPtr): WindowPtr;
  478.  
  479. (*******************************************************************************
  480. *
  481. * MakeDocumentPicture - Create a PICT with a document's image in it
  482. *
  483. * This routine creates a QuickDraw Picture that, when drawn, reproduces a
  484. * document as if the document were drawn in an active window.
  485. *
  486. *******************************************************************************)
  487.  
  488. FUNCTION MakeDocumentPicture(theDoc: DocumentPtr): PicHandle;
  489.  
  490. (*******************************************************************************
  491. *
  492. * DoContentClick - Handle mouseDown events in document windows
  493. *
  494. * Sample.p calls this routine when there's a mouse down in the content Region
  495. * of a document window.  DoContentClick changes the active light to the one
  496. * clicked on if different than the current active light, and presents the
  497. * "Modify Circle" dialog if that circle was double-clicked.
  498. *
  499. *******************************************************************************)
  500.  
  501. PROCEDURE DoContentClick(window: WindowPtr; event: EventRecord);
  502.  
  503. (*******************************************************************************
  504. *
  505. * DoHelp - Handle balloon help
  506. *
  507. * If the mouse is over the frontmost window and there's a mouse-moved event
  508. * and balloon help is on, Sample.p calls DoHelp to present the new balloon
  509. * for the new mouse location, and to calculate a new mouseMoved Region (the
  510. * second parameter) so that we get called again if we need to change balloons.
  511. *
  512. *******************************************************************************)
  513.  
  514. PROCEDURE DoHelp(where: Point; mouseRgn: RgnHandle);
  515.  
  516. (*******************************************************************************
  517. *
  518. * DoNew - Create a new untitled window
  519. *
  520. * DoNew creates a new, default document and a window that draws it, returning
  521. * the window pointer.
  522. *
  523. *******************************************************************************)
  524.  
  525. FUNCTION DoNew: WindowPtr;
  526.  
  527. (*******************************************************************************
  528. *
  529. * DoPageSetup - present the Page Setup dialog for a window's print record
  530. *
  531. * This routine extracts the window's document's print record and conducts
  532. * the standard style dialog with the user (if possible).  It's provided as
  533. * a shell to the Print unit's PageSetup routine so that anyone wanting
  534. * to do this with a given window doesn't have to dig into the document
  535. * structure to get the print record.
  536. *
  537. *******************************************************************************)
  538.  
  539. FUNCTION DoPageSetup(theWindow: WindowPtr): BOOLEAN;
  540.  
  541. (*******************************************************************************
  542. *
  543. * DoPrint - print a document window
  544. *
  545. * This routine extracts the window's document's print record and conducts
  546. * the standard job dialog with the user (if possible), printing the window's
  547. * contents if the user confirmed or if the job dialog couldn't be done.
  548. * It's provided as a shell to the Print unit's Print routine so that anyone 
  549. * wanting to do this with a given window doesn't have to dig into the document
  550. * structure to get the print record.
  551. *
  552. *******************************************************************************)
  553.  
  554. FUNCTION DoPrint(theWindow: WindowPtr): BOOLEAN;
  555.  
  556. (*******************************************************************************
  557. *
  558. * DoPrintFile - print a document on disk without opening a window for it
  559. *
  560. * This routine handles the expected Apple Event 'pdoc' behavior -- it fetches
  561. * a document from disk and prints it but doesn't open a window for it.
  562. *
  563. *******************************************************************************)
  564.  
  565. PROCEDURE DoPrintFile(theFile: FileLikeSpecPtr; theMergePrintRecord: THPrint);
  566.  
  567. (*******************************************************************************
  568. *
  569. * DoSave - save a document to disk
  570. *
  571. * This routine saves a document to disk.  If it's not already part of an open
  572. * file, it prompts for a place to save using the Standard File Package.  If
  573. * all goes well, the return value is TRUE and the window's title is changed to
  574. * reflect the saved document's name.
  575. *
  576. *******************************************************************************)
  577.  
  578. FUNCTION DoSave(theWindow: WindowPtr): BOOLEAN;
  579.  
  580. (*******************************************************************************
  581. *
  582. * DoSaveAs - save a document to disk, always prompting for location
  583. *
  584. * This routine saves a document to disk.  It prompts for a place to save using 
  585. * the Standard File Package.  If all goes well, the return value is TRUE and the 
  586. * window's title is changed to reflect the saved document's name.  In addition,
  587. * any old file that this document came from is closed.  If there's an error,
  588. * the original file (if any) remains open.
  589. *
  590. *******************************************************************************)
  591.  
  592. FUNCTION DoSaveAs(theWindow: WindowPtr): BOOLEAN;
  593.  
  594. (*******************************************************************************
  595. *
  596. * DoRevert - restore a document to its last state saved to disk
  597. *
  598. * DoRevert asks the user if he really wants to discard any changes to the file
  599. * he's made since it was last saved, and if he confirms, it closes the file
  600. * and refetches the document from the original file, redrawing the window.
  601. * It returns TRUE if no errors happened while doing this, whether the user
  602. * confirmed the revert operation or not.
  603. *
  604. *******************************************************************************)
  605.  
  606. FUNCTION DoRevert(theWindow: WindowPtr): BOOLEAN;
  607.  
  608. (*******************************************************************************
  609. *
  610. * DoOpenDocument - Create a window for a document from disk
  611. *
  612. * This routine reads a document from disk and creates a new window representing
  613. * it.  If the parameter is not NIL, it's interpreted as a FileLikeSpecPtr
  614. * describing the file to open.  If it is NIL, DoOpenDocument prompts the
  615. * use with Standard File to select a file to open.
  616. *
  617. *******************************************************************************)
  618.  
  619. FUNCTION DoOpenDocument(theFileSpec: FileLikeSpecPtr): WindowPtr;
  620.  
  621. (*******************************************************************************
  622. *
  623. * GetDocumentFromFile - make a document structure from a disk file
  624. *
  625. * This routine reads a file from disk and constructs a document structure from
  626. * it.  Like DoOpenDocument, if theFile is NIL, it calls Standard File to ask
  627. * which file to read from disk.  It returns TRUE if the document was succesfully
  628. * constructed from the disk file.
  629. *
  630. *******************************************************************************)
  631.  
  632. FUNCTION GetDocumentFromFile(theFile: FileLikeSpecPtr;
  633.                              theDoc: DocumentPtr): BOOLEAN;
  634.  
  635. (*******************************************************************************
  636. *
  637. * MakeEmptyDoc - Create a standard, default document structure based on
  638. *                 preferences and the defaults in our resource fork
  639. *
  640. *******************************************************************************)
  641.  
  642. FUNCTION MakeEmptyDoc: DocumentPtr;
  643.  
  644. (*******************************************************************************
  645. *
  646. * ChangeCircleOptions - conduct the "Modify Circle" dialog.
  647. *
  648. * If enough memory is available and it's OK to interact with the user, this
  649. * routine calls DoCircleOptions in the SampleDialog unit to present the
  650. * loverly "Modify Circle" modal dialog, returning TRUE if the user confirmed
  651. * changes to the circle.
  652. *
  653. *******************************************************************************)
  654.  
  655. FUNCTION ChangeCircleOptions(VAR circle: CircleRec): BOOLEAN;
  656.  
  657. IMPLEMENTATION
  658.  
  659. {$I TrafficLights.inc1.p}
  660.  
  661. END. { unit TrafficLights }
  662.